package utils
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.system.Capabilities;

	import mx.core.FlexGlobals;
	import mx.styles.CSSStyleDeclaration;

	import spark.components.WindowedApplication;

	public class AppUtils
	{

		private static var _app:WindowedApplication;
		private static var _stage:Stage;

		public static function setUpAPP(app:WindowedApplication):void
		{
			//设置居中
			app.nativeWindow.x=(Capabilities.screenResolutionX - app.width) / 2;
			app.nativeWindow.y=(Capabilities.screenResolutionY - app.height) / 2;
			//设置全局样式
			var list:Array=FlexGlobals.topLevelApplication.styleManager.selectors;
			for (var i:int=0; i < list.length; i++)
			{
				var cssDeclaration:CSSStyleDeclaration=FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration(list[i]);
				cssDeclaration.setStyle("fontFamily", "微软雅黑");
				cssDeclaration.setStyle("fontSize", "12");
			}
			app.statusText.setStyle("fontSize", "12");
			app.statusText.text="准备就绪";
			_app=app;
			//处理获得stage
			if (_app.stage)
			{
				_stage=_app.stage;
			}
			else
			{
				_app.addEventListener(Event.ADDED_TO_STAGE, function(e:Event):void
				{
					_stage=_app.stage;
				});
			}
		}

		public static function get stage():Stage
		{
			return _stage;
		}

		public static function get app():WindowedApplication
		{
			return _app;
		}
	}
}
